Switch board (framework)

Switch Board is a MVC framework written for PHP. Its original concepts were taken from a preexisting ColdFusion/PHP framework called Fusebox. Its evolution through development has greatly changed its structure to have very little resemblance to Fusebox other than slight functionality of the switch, settings and template files.

Contents

Description

The current release of Switch Board is Switch Board with Routing 2.0.1. This version was released on December 25, 2006 by the developer Daniel Slaughter.

Switch Board has three sub-directories from its root. These sub-directories are the control, model and view. When a page is called from a Browser the PHP Server executes the control, model and then view file before displaying the resulting content to the called Browser. This separation of MVC is seamless to the end user.

Core

The core file is the brains behind everything. This file (sb_core.php) consists of 66 lines of code. The core file executes in the following manner:

1. The URL is parsed to determine what circuit and page to gather the control/model/view pages from.
2. The Settings file is then included which contains any global variables. If a circuit other than the root was found in the URL then its settings file is as well included here.
3. The Switch file from the root or circuit is included (but not both).
4. PHP determines if control/page.php exists and includes it (where page equals the file the browser is attempting to access)
5. PHP determines if model/page.php exists and includes it
6. PHP determines if view/page.php exists and includes it
7. Any content generated from the control/model/view is then embedded in the template and displayed to the Browser. If no content was generated, the designated error page is included instead (specified in the settings file).
Settings

The settings is held in a file called sb_settings.php in the root of the Switch Board files. This file is where any global variables are held. For instance, the configuration variables of Switch Board are located here. You may add any additional variables you wish to this file that your application will use. The settings file are called prior to any other file from the sb_core.php file.

Switch

The switch is held in a file called sb_switch.php in the root of the Switch Board files. This file is a simple PHP switch-case that handles any global variables to the individual page (such as the page title, if the page redirects, and exit actions: links from this page). Please note: you do not need to have include statements for the control/model/view files here. Switch Board assumes if they exist they should be included (this greatly increases development time and ensures file naming schemes). The switch file is called before the control/model/view files are included.

Control

Processes and responds to events, typically user actions, and may invoke changes on the model. In Switch Board the control is meant to make inserts/updates to a database or other file structure. These pages are typically called from the posting of a form.

Model

The model is another name for the domain layer. The model in Switch Board is where database select statements are pooled. Calculations can also be done here to data before it is presented to the view file for display.

View

Renders the model into a form suitable for interaction, typically a user interface element. In Switch Board the view page contains the display generated from the data retrieved in the model. Only the information physically presented to the Browser should be held here (such as XHTML, HTML, CSS). However, for debugging purposes content can be displayed to the Browser through the control and model but is not suggested for final release.

Template

The template is held in a file called sb_template.php in the root of the Switch Board files. This template file contains the wrapper XHTML/HTML for the content generated from a page call to Switch Board from the Browser. The template is the last file to include. There are parameters you can use to ignore the template (ie: $sb['useTemplate'] = false).

Advantages of Switch Board

Hello World

You can then access this Hello World application by going to an address such as: http://domain.com/helloworld.htm

Built in capabilities

$sb['redirect'] = "http://domain.com/control/page.htm";
// turn on/off authentication
$sb['useAuthentication'] = true
// what variable to check if it exists (such as a session that only exists if they're "logged in")
$sb['hasAuthentication'] = isSet($_SESSION['auth']);
// the array of pages you should only be able to access without authentication: include circuitpath/extension
$sb['noAuthentication'] = array("index.htm","apple.htm");
// you will be redirected here if you attempt to access an internal page that you do not have authentication to
$sb['noAuthenticationRedirect'] = "/sb_20/index.htm?error=authentication";
// if you are authenticated and attempt to access a non-authenticated page, redirect to here (such as the login page)
$sb['authenticationRedirect'] = "/sb_20/hasauthentication.htm";
$sb['useTemplate'] = true;
$sb['useControl'] = true;
$sb['useModel'] = true;
$sb['useView'] = true;
// this page will be included if someone types in an incorrect page address.
$sb['errorPage'] = "error404";
$sb['fileExt'] = ".htm";
$sb['defaultPage'] = "index";

External links

References